package cnpm02.j2ee.group3.logic.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import org.jboss.seam.Component;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

import cnpm02.j2ee.group3.logic.dao.impl.SoldTicketDao;
import cnpm02.j2ee.group3.logic.utils.ATSMUtils;
import cnpm02.j2ee.group3.model.SoldTicket;
import cnpm02.j2ee.group3.model.SoldTicketStatus;

@Name("soldTicket")
public class SoldTicketBean implements Serializable {
	private static final long serialVersionUID = 1L;
	
	@In
	private SoldTicketDao soldTicketDao;
	
	private List<SoldTicketDTO> soldTickets = new ArrayList<SoldTicketDTO>();
	private List<SelectItem> status = new ArrayList<SelectItem>();
	private String selectedStatus;
	
	@Create
	public void init() throws Exception {
		for(SoldTicket st : soldTicketDao.selectAll()) {
			SoldTicketDTO std = new SoldTicketDTO(st);
			soldTickets.add(std);
		}
	}

	public void doSave() {
		
	}
	
	public List<SoldTicketDTO> getSoldTickets() {
		return soldTickets;
	}

	public void setSelectedStatus(String selectedStatus) {
		this.selectedStatus = selectedStatus;
	}

	public String getSelectedStatus() {
		return selectedStatus;
	}

	public void setStatus(List<SelectItem> status) {
		this.status = status;
	}

	public List<SelectItem> getStatus() {
		ATSMUtils atsmUtils = (ATSMUtils) Component.getInstance("atsmUtils");
		for (SoldTicketStatus stt : SoldTicketStatus.values()) {
			String st = stt.getNameByLanguage(atsmUtils.getCurrentLanguage());
			status.add(new SelectItem(st, st));
		}
		return status;
	}
}
